﻿package net.wangit.dev.unit;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.util.Checker;
import net.wangit.view.unit.UnitFactory;

public class UnitPreviewUI implements UnitInterceptor {

	public UnitPreviewUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String domain = ac.getRequestParameter("domain");
		String unitId = ac.getRequestParameter("uid");
		if (!Checker.isEmpty(unitId) && !Checker.isEmpty(domain)) {
			unit.setShowMode("e");
			Unit subUnit = UnitFactory.getUnit(ac, domain, unitId, unit
					.getPage());
			subUnit.setShowMode("e");
			unit.getElement("unit").setObject(subUnit);
		}
		return unit.write(ac);
	}
}
